<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    dialog{
        width: 400px;
        height: 400px;
        border: 1px solid #f0f0f0;
        border-radius: 20px;
    }
    .content{
        height: 300px;
        width: 100%;
        padding: 20px;
        box-sizing: border-box;
    }
    h2{
        text-align: center;
    }
</style>

<body>
    <button id="open" onclick="show()">show</button>
    <dialog id="dialog">
        <h2>标题</h2>
        <div class="content">这是一个模态框</div>
        <button id="close" onclick="hide()">close</button>
    </dialog>

    
</body>
<script>
        var dialog=document.getElementById("dialog")
        function show(){
            dialog.showModal();
        }
        function hide(){  
            dialog.close();
        }    
</script>
</html>